<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of VMT_ReadFiles</title>
  <meta name="keywords" content="VMT_ReadFiles">
  <meta name="description" content="Read in multiple ASCII output files from WinRiver or WinRiverII.">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../m2html.css">
  <script type="text/javascript">
    if (top.frames.length == 0) { top.location = "../index.html"; };
  </script>
</head>
<body>
<a name="_top"></a>
<!-- menu.html VMT_4.0_dev -->
<h1>VMT_ReadFiles
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>Read in multiple ASCII output files from WinRiver or WinRiverII.</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function [zPathName,zFileName,savefile,A,z] = VMT_ReadFiles(zPathName,zFileName) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment"> Read in multiple ASCII output files from WinRiver or WinRiverII.

 Added save path functionality (PRJ, 6-23-10)
 (adapted from code by J. Czuba)

 See also: tfile (utils folder)

 P.R. Jackson, USGS, 12-11-08
 Last modified: F.L. Engel, USGS, 2/20/2013</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../matlabicon.gif)">
</ul>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="VMT.html" class="code" title="function varargout = VMT(varargin)">VMT</a>	--- THE VELOCITY MAPPING TOOLBOX ---</li></ul>
<!-- crossreference -->

<h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="#_sub1" class="code">function A = initStructure(z)</a></li></ul>

<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [zPathName,zFileName,savefile,A,z] = VMT_ReadFiles(zPathName,zFileName)</a>
0002 <span class="comment">% Read in multiple ASCII output files from WinRiver or WinRiverII.</span>
0003 <span class="comment">%</span>
0004 <span class="comment">% Added save path functionality (PRJ, 6-23-10)</span>
0005 <span class="comment">% (adapted from code by J. Czuba)</span>
0006 <span class="comment">%</span>
0007 <span class="comment">% See also: tfile (utils folder)</span>
0008 <span class="comment">%</span>
0009 <span class="comment">% P.R. Jackson, USGS, 12-11-08</span>
0010 <span class="comment">% Last modified: F.L. Engel, USGS, 2/20/2013</span>
0011 
0012 
0013 
0014 <span class="comment">%% Read in multiple ASCII .TXT Files</span>
0015 <span class="comment">% This program reads in multiple ASCII text files into a single structure.</span>
0016 
0017 <span class="keyword">if</span> ischar(zFileName)
0018     zFileName = {zFileName};
0019 <span class="keyword">elseif</span> iscellstr(zFileName)
0020     zFileName = sort(zFileName);       
0021 <span class="keyword">end</span>
0022 <span class="comment">%msgbox('Loading Data...','VMT Status','help','replace')</span>
0023 
0024 <span class="comment">%% Read in Selected Files</span>
0025 <span class="comment">% Initialize the data structure</span>
0026 z = length(zFileName);
0027 A = <a href="#_sub1" class="code" title="subfunction A = initStructure(z)">initStructure</a>(z);
0028 
0029 <span class="comment">% Begin master loop</span>
0030 <span class="keyword">for</span> zi=1:z
0031     <span class="comment">% Open txt data file</span>
0032     fileName = fullfile(zPathName,zFileName{zi});
0033 
0034     <span class="comment">% screenData 0 leaves bad data as -32768, 1 converts to NaN</span>
0035     <span class="comment">% ignoreBS 0 processes BS data, 1 ignores it</span>
0036     screenData = 1;
0037     ignoreBS   = 0;
0038 
0039     <span class="comment">% tfile reads the data from an RDI ASCII output file and puts the</span>
0040     <span class="comment">% data in a Matlab data structure with major groups of:</span>
0041     <span class="comment">% Sup - supporing data</span>
0042     <span class="comment">% Wat - water data</span>
0043     <span class="comment">% Nav - navigation data including GPS.</span>
0044     <span class="comment">% Sensor - Sensor data</span>
0045     <span class="comment">% Q - discharge related data</span>
0046 
0047     <span class="keyword">try</span>
0048         [A(zi)]=tfile(fileName,screenData,ignoreBS);
0049         
0050         [~,file_name,extension] = fileparts(fileName);
0051         new_message = strrep([<span class="string">'Loading file '</span> file_name extension],<span class="string">'_'</span>,<span class="string">'\_'</span>);
0052 <span class="comment">%         if ishandle(h_waitbar)</span>
0053 <span class="comment">%             waitbar(zi/z,h_waitbar,new_message)</span>
0054 <span class="comment">%         else</span>
0055 <span class="comment">%             h_waitbar = waitbar(zi/z,new_message,'Name','Loading Files');</span>
0056 <span class="comment">%         end</span>
0057 
0058     <span class="keyword">catch</span> err
0059         erstg = {<span class="string">'                                                      '</span>,<span class="keyword">...</span>
0060                  <span class="string">'An unknown error occurred when reading the ASCII file.'</span>,<span class="keyword">...</span>
0061                  <span class="string">'Occasionally this occurs due to a corrupt ASCII file with'</span>,<span class="keyword">...</span>
0062                  <span class="string">'formatting errors. Please regenerate the ASCII file and '</span>,<span class="keyword">...</span>
0063                  <span class="string">'retry loading into VMT. An error may also occur if there '</span>,<span class="keyword">...</span>
0064                  <span class="string">'are white spaces or special characters (e.g. *?&lt;&gt;|) in '</span>,<span class="keyword">...</span>
0065                  <span class="string">'the filenames or paths. Ensure no such spaces or '</span>,<span class="keyword">...</span>
0066                  <span class="string">'characters exist and try loading the files again.'</span>};
0067         errordlg([zFileName(zi) erstg],<span class="string">'VMT Status'</span>,<span class="string">'replace'</span>);
0068         rethrow(err)
0069         <span class="keyword">break</span>
0070     <span class="keyword">end</span>
0071     
0072     <span class="comment">% Check the units to ensure they are metric</span>
0073     
0074     <span class="keyword">if</span> ~strcmp(A(zi).Sup.units,<span class="string">'cm'</span>)
0075         erstg = {<span class="string">'                                                      '</span>,<span class="keyword">...</span>
0076                  <span class="string">'Units in ASCII file are not metric.  VMT only accepts data'</span><span class="keyword">...</span>
0077                  <span class="string">'in metric units.  Please change the units in WinRiver II'</span><span class="keyword">...</span>
0078                  <span class="string">'and export your ASCII files again before reloading into VMT.'</span>};
0079         errordlg([zFileName(zi) erstg],<span class="string">'VMT Status'</span>,<span class="string">'replace'</span>);
0080         error(<span class="string">'VMT:unitsChk'</span>, <span class="string">'Input not in metic units'</span>)
0081     <span class="keyword">end</span>
0082 
0083 <span class="keyword">end</span>
0084 
0085 <span class="comment">% Get rid of the waitbar</span>
0086 <span class="comment">% if ishandle(h_waitbar)</span>
0087 <span class="comment">%     delete(h_waitbar)</span>
0088 <span class="comment">% end</span>
0089 
0090 <span class="comment">% Save data returned by tfile to .mat with same prefix as ASCII</span>
0091 [file_root_name,the_rest] = strtok(zFileName,<span class="string">'_'</span>);
0092 file_numbers = strtok(the_rest,<span class="string">'_'</span>);
0093 
0094 save_dir = fullfile(zPathName,<span class="string">'VMTProcFiles'</span>);
0095 [~,mess,~] = mkdir(save_dir); 
0096 <span class="comment">% disp(mess)</span>
0097 
0098 savefile = [file_root_name{1} <span class="string">'_'</span> file_numbers{1} <span class="string">'_'</span> file_numbers{end} <span class="string">'.mat'</span>];
0099 savefile = fullfile(save_dir,savefile);
0100 
0101 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%</span>
0102 <span class="comment">% Embedded Functions %</span>
0103 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%</span>
0104 
0105 <a name="_sub1" href="#_subfunctions" class="code">function A = initStructure(z)</a>
0106    Sup = struct(<span class="string">'absorption_dbpm'</span>,{}, <span class="keyword">...</span>
0107                 <span class="string">'bins'</span>,{}, <span class="keyword">...</span>
0108                 <span class="string">'binSize_cm'</span>,{}, <span class="keyword">...</span>
0109                 <span class="string">'nBins'</span>,{}, <span class="keyword">...</span>
0110                 <span class="string">'blank_cm'</span>,{}, <span class="keyword">...</span>
0111                 <span class="string">'draft_cm'</span>,{}, <span class="keyword">...</span>
0112                 <span class="string">'ensNo'</span>,{}, <span class="keyword">...</span>
0113                 <span class="string">'nPings'</span>,{}, <span class="keyword">...</span>
0114                 <span class="string">'noEnsInSeg'</span>,{}, <span class="keyword">...</span>
0115                 <span class="string">'noe'</span>,{}, <span class="keyword">...</span>
0116                 <span class="string">'note1'</span>,{}, <span class="keyword">...</span>
0117                 <span class="string">'note2'</span>,{}, <span class="keyword">...</span>
0118                 <span class="string">'intScaleFact_dbpcnt'</span>,{}, <span class="keyword">...</span>
0119                 <span class="string">'intUnits'</span>,{}, <span class="keyword">...</span>
0120                 <span class="string">'vRef'</span>,{}, <span class="keyword">...</span>
0121                 <span class="string">'wm'</span>,{}, <span class="keyword">...</span>
0122                 <span class="string">'units'</span>,{}, <span class="keyword">...</span>
0123                 <span class="string">'year'</span>,{}, <span class="keyword">...</span>
0124                 <span class="string">'month'</span>,{}, <span class="keyword">...</span>
0125                 <span class="string">'day'</span>,{}, <span class="keyword">...</span>
0126                 <span class="string">'hour'</span>,{}, <span class="keyword">...</span>
0127                 <span class="string">'minute'</span>,{}, <span class="keyword">...</span>
0128                 <span class="string">'second'</span>,{}, <span class="keyword">...</span>
0129                 <span class="string">'sec100'</span>,{}, <span class="keyword">...</span>
0130                 <span class="string">'timeElapsed_sec'</span>,{}, <span class="keyword">...</span>
0131                 <span class="string">'timeDelta_sec100'</span>,{});
0132    Wat = struct(<span class="string">'binDepth'</span>,{}, <span class="keyword">...</span>
0133                 <span class="string">'backscatter'</span>,{}, <span class="keyword">...</span>
0134                 <span class="string">'vDir'</span>,{}, <span class="keyword">...</span>
0135                 <span class="string">'vMag'</span>,{}, <span class="keyword">...</span>
0136                 <span class="string">'vEast'</span>,{}, <span class="keyword">...</span>
0137                 <span class="string">'vError'</span>,{}, <span class="keyword">...</span>
0138                 <span class="string">'vNorth'</span>,{}, <span class="keyword">...</span>
0139                 <span class="string">'vVert'</span>,{}, <span class="keyword">...</span>
0140                 <span class="string">'percentGood'</span>,{});
0141    Nav = struct(<span class="string">'bvEast'</span>,{}, <span class="keyword">...</span>
0142                 <span class="string">'bvError'</span>,{}, <span class="keyword">...</span>
0143                 <span class="string">'bvNorth'</span>,{}, <span class="keyword">...</span>
0144                 <span class="string">'bvVert'</span>,{}, <span class="keyword">...</span>
0145                 <span class="string">'depth'</span>,{}, <span class="keyword">...</span>
0146                 <span class="string">'dsDepth'</span>,{}, <span class="keyword">...</span>
0147                 <span class="string">'dmg'</span>,{}, <span class="keyword">...</span>
0148                 <span class="string">'length'</span>,{}, <span class="keyword">...</span>
0149                 <span class="string">'totDistEast'</span>,{}, <span class="keyword">...</span>
0150                 <span class="string">'totDistNorth'</span>,{}, <span class="keyword">...</span>
0151                 <span class="string">'altitude'</span>,{}, <span class="keyword">...</span>
0152                 <span class="string">'altitudeChng'</span>,{}, <span class="keyword">...</span>
0153                 <span class="string">'gpsTotDist'</span>,{}, <span class="keyword">...</span>
0154                 <span class="string">'gpsVariable'</span>,{}, <span class="keyword">...</span>
0155                 <span class="string">'gpsVeast'</span>,{}, <span class="keyword">...</span>
0156                 <span class="string">'gpsVnorth'</span>,{}, <span class="keyword">...</span>
0157                 <span class="string">'lat_deg'</span>,{}, <span class="keyword">...</span>
0158                 <span class="string">'long_deg'</span>,{}, <span class="keyword">...</span>
0159                 <span class="string">'nSats'</span>,{}, <span class="keyword">...</span>
0160                 <span class="string">'hdop'</span>,{});
0161    Sensor = struct(<span class="string">'pitch_deg'</span>,{}, <span class="keyword">...</span>
0162                    <span class="string">'roll_deg'</span>,{}, <span class="keyword">...</span>
0163                    <span class="string">'heading_deg'</span>,{}, <span class="keyword">...</span>
0164                    <span class="string">'temp_degC'</span>,{});
0165      Q = struct(<span class="string">'endDepth'</span>,{}, <span class="keyword">...</span>
0166                 <span class="string">'endDist'</span>,{}, <span class="keyword">...</span>
0167                 <span class="string">'bot'</span>,{}, <span class="keyword">...</span>
0168                 <span class="string">'end'</span>,{}, <span class="keyword">...</span>
0169                 <span class="string">'meas'</span>,{}, <span class="keyword">...</span>
0170                 <span class="string">'start'</span>,{}, <span class="keyword">...</span>
0171                 <span class="string">'top'</span>,{}, <span class="keyword">...</span>
0172                 <span class="string">'unit'</span>,{}, <span class="keyword">...</span>
0173                 <span class="string">'startDepth'</span>,{}, <span class="keyword">...</span>
0174                 <span class="string">'startDist'</span>,{});
0175             A(z).Sup = Sup;
0176             A(z).Wat = Wat;
0177             A(z).Nav = Nav;
0178             A(z).Sensor = Sensor;
0179             A(z).Q = Q;
0180             
0181             <span class="comment">% [EOF] initStructure</span></pre></div>
<hr><address>Generated on Thu 21-Mar-2013 09:32:01 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" target="_parent">m2html</a></strong> &copy; 2005</address>
</body>
</html>